package com.gxa.learning.portal.controller;

import com.gxa.learning.core.common.ExceptionCode;
import com.gxa.learning.core.common.JsonResult;
import com.gxa.learning.core.exception.BusinessException;
import com.gxa.learning.portal.service.MessageService;
import com.gxa.learning.portal.service.ProjectApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.List;
import java.util.Map;

/**
 * @author lijianmin
 * @date 2021/12/09  14:36:23
 */
@RestController
@RequestMapping("/msg")
@Api(tags = "消息的接口")
public class MessageController {

    @Resource
    private MessageService messageService;

    @Autowired
    private ProjectApplyService projectApplyService;

    /**
     * 获取当前用户的所有考试的接口,如果项目编号不为空 则根据用户编号和项目编号查询考试
     *
     * @return 返回找到列表
     */
    @GetMapping("/getExam")
    @ApiOperation("获取当前用户的所有考试的接口,如果项目编号不为空 则根据用户编号和项目编号查询考试")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户编号", dataType = "long", paramType = "query"),
            @ApiImplicitParam(name = "projectId", value = "项目编号", dataType = "long", paramType = "query")
    })
    public Map<String, Object> getExamList(@RequestParam("userId") Long userId, @RequestParam(value = "projectId", required = false) Long projectId) throws BusinessException, ParseException {
        if (userId == null) {
            throw new BusinessException(ExceptionCode.ARGUMENTS_NOT_NULL);
        }
        List<Map<String, Object>> maps = messageService.selectUserTest(userId, projectId);

        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(maps);
        jsonResult.setMsg("查询成功");
        return jsonResult.getDataMap();
    }

    @GetMapping("/getAppy")
    @ApiOperation("获取当前用户所有报名培训的接口")
    @ApiImplicitParam(name = "id", value = "id", dataType = "long", paramType = "query")
    public Map<String, Object> getAppy(@RequestParam("id") Long id) throws BusinessException {
        if (id == null) {
            throw new BusinessException(ExceptionCode.ARGUMENTS_NOT_NULL);
        }

        List<Map<String, Object>> maps = projectApplyService.selectRegistration(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(maps);
        return jsonResult.getDataMap();

    }


    @GetMapping("/getFeedback")
    @ApiOperation("获取当前用户的所有反馈的接口")
    @ApiImplicitParam(name = "id", value = "id", dataType = "long", paramType = "query")
    public Map<String, Object> getFeedback(@RequestParam("id") Long id) throws BusinessException {
        List<Map<String, Object>> maps = messageService.selectUserFeedback(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(maps);
        return jsonResult.getDataMap();
    }


}
